﻿using RecruitStudents.Client.BLL;
using RecruitStudents.Utility;
using RecruitStudents.Utility.Helper;
using RecruitStudents.Utility.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace RecruitStudents.Client.Base
{
    public partial class Base_ExamScoreTypeItemForm_Option : BaseForm
    {
        string ExamScoreTypeID = string.Empty;
        string ExamScoreTypeID_Detail = string.Empty;
        TB_Sys_ExamScoreTypeItem model = null;
        ServiceBase service = new ServiceBase();
        public Base_ExamScoreTypeItemForm_Option(string examScoreTypeID, string examScoreTypeID_Detail)
        {
            InitializeComponent();
            ExamScoreTypeID = examScoreTypeID;
            ExamScoreTypeID_Detail = examScoreTypeID_Detail;
            if (examScoreTypeID_Detail.Length > 0)
            {
                model = service.GetExamScoreTypeModel_Detail(examScoreTypeID_Detail);
                if (model != null)
                {
                    //txtNO.Enabled = false;
                    model.Attach();
                    txtName.Text = model.SpecialityLevelTypeItemName;
                    //txtNO.Text = model.SpecialityLevelTypeItemNO;
                    txtMin.Text = model.MinScore.ToSafeString();
                    txtMax.Text = model.MaxScore.ToSafeString();
                    txtSort.Text = model.Sort.ToSafeString();
                    txtWeight.Text = model.Weight.ToSafeString();
                }
            }
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            //if (string.IsNullOrEmpty(txtNO.Text))
            //{
            //    DevHelper.ShowInfoMessageBox("请输入编码！");
            //    txtNO.Focus();
            //    return;
            //}
            if (string.IsNullOrEmpty(txtName.Text))
            {
                DevHelper.ShowInfoMessageBox("请输入名称！");
                txtName.Focus();
                return;
            }
            if (model == null)
            {
                model = new TB_Sys_ExamScoreTypeItem();
            }
            model.ExamScoreTypeID = ExamScoreTypeID;
            model.ExamYear = SessionerHelper.SystemYear;
            model.MaxScore = txtMax.Text.ToSafeDecimal();
            model.MinScore = txtMin.Text.ToSafeDecimal();
            model.Sort = txtSort.Text.ToSafeInt();
            model.SpecialityLevelTypeItemName = txtName.Text;
            //model.SpecialityLevelTypeItemNO = txtNO.Text;
            model.Weight = txtWeight.Text.ToSafeDecimal();
            if (service.SaveExamScoreType_Detail(model))
            {
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }
    }
}
